from functools import wraps

from flask import current_app
from flask import g
from flask import session


def myfilter(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return "second"
    elif index == 3:
        return 'third'
    else:
        return ''


def login_user_info(func):
    @wraps(func)
    def call_func(*args, **kwargs):
        user_id = session.get('user_id')
        user = None
        if user_id:
            try:
                from info.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user
        return func(*args, **kwargs)

    return call_func
